<?php
// +----------------------------------------------------------------------
// | Hook.
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.suckseed.cn, All rights reserved.
// +----------------------------------------------------------------------
// | Author: wjf <184521508@qq.com> 2017-07-01
// +----------------------------------------------------------------------

namespace app\admin\controller;

use app\admin\model\Hook as HookModel;
use app\admin\model\Plugin;
use app\admin\model\HookPlugin;

use wjf\controller\AdminBase;

/**
 * Class HookController 钩子管理控制器
 * @package app\admin\controller
 */
class Hook extends AdminBase
{
    /**
     * 钩子管理
     * @adminMenu(
     *     'name'   => '钩子管理',
     *     'parent' => 'admin/Plugin/default',
     *     'display'=> true,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '钩子管理',
     *     'param'  => ''
     * )
     */
    public function index()
    {
        $hookModel = new HookModel();
        $hooks = $hookModel->select();
        $this->assign('hooks', $hooks);
        return $this->fetch();

    }

    /**
     * 钩子插件管理
     * @adminMenu(
     *     'name'   => '钩子插件管理',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> true,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '钩子插件管理',
     *     'param'  => ''
     * )
     */
    public function plugins()
    {
        $hook = $this->request->param('hook');
        $pluginModel = new Plugin();
        $plugins     = $pluginModel->field('a.*,b.hook,b.plugin,b.list_order,b.status as hook_plugin_status,b.id as hook_plugin_id')->alias('a')->join('__HOOK_PLUGIN__ b', 'a.name = b.plugin')->where('b.hook', $hook)->select();
        $this->assign('plugins',$plugins);
        return $this->fetch();
    }

    public function pluginListOrder()
    {
        $hookPluginModel = new HookPlugin();
        parent::listOrders($hookPluginModel);

        $this->success("排序更新成功！");
    }
}